<template>
  <div class="customerStatistics-big">
    <div class="customerStatistics" v-if="!showMonitorData">
      <div class="title">指定成员数据<span class="icon">指标说明</span>
        <span class="tips">加入监测后，次日开始监测数据，并可查看监测数据</span>
        <div class="time">更新时间：2024-04-09 02:42:20</div>
      </div>
      <div class="formGroup">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="130px">
          <el-button type="primary" icon="el-icon-plus" size="small"  plain style="margin-right: 10px" @click="handerAdd">监测成员</el-button>
          <el-form-item prop="userName2">
            <el-select v-model="queryParams.userName2" size="small" filterable placeholder="全部账号" @change="handleQuery">
              <el-option
                v-for="item in userList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="userName2">
            <div class="search">
              <el-input v-model="queryParams.userName1" placeholder="搜索群成员" clearable/>
              <el-button icon="el-icon-search" size="small"></el-button>
            </div>
          </el-form-item>
        </el-form>
        <el-button  plain size="small">导出数据</el-button>
      </div>
      <div class="tableAnalysis">
        <el-table
          :data="tableDataList"
          ref="customerMgtList"
        >
          <el-table-column
            :label="item.label"
            align="center"
            v-for="(item, index) in tableColumns"
            :key="index"
            :prop="item.key"
            :min-width="item.minWidth ? item.minWidth : ``"
            :fixed="item.fixed ? item.fixed : false"
            :show-overflow-tooltip="true"
          >
            <template slot="header" v-if="item.showHeaderTip">
              <div>
                {{item.label}}
                <el-tooltip effect="dark" :content="item.showHeaderTip" placement="top">
                  <span><i class="el-icon-question"></i></span>
                </el-tooltip>
              </div>
            </template>
            <!--用于表格自定义-->
            <template slot-scope="scope">
              <div class="userInfo" v-if="item.key==`name`">
                <img src="@/assets/images/profile.jpg"/>
                <div class="user-big">
                  <div class="name">肖洁</div>
                </div>
              </div>
              <div v-else>{{ scope.row[item.key] }}</div>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="220">
            <template slot-scope="scope">
              <el-button @click="handleSetting(scope.row)" type="text" size="small">监测数据</el-button>
              <el-button type="text" size="small">取消监测</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
      <!--    选择监测人员-->
      <addUser v-if="showAddUser" :visableIf.sync="showAddUser"></addUser>

    </div>
    <monitorData v-else></monitorData>
  </div>


</template>
<script>
import {listUser} from "@/api/system/user";
import {getTime} from "@/utils";

export default {
  name: "specifyMemberData",
  components: {
    'addUser': () => import('./addUser.vue'),
    'monitorData': () => import('./monitorData.vue'),
  },
  data() {
    return {
      queryParams: {},
      showMonitorData:false,//是否展示监测数据
      timeRange: [],
      showAddUser:false,
      dataList:[
        {value:1000,name:'扫一扫',},
        {value:1200,name:'手机号',},
        {value:1200,name:'名片',},
        {value:600,name:'群聊',},
        {value:800,name:'微信好友',},
        {value:900,name:'第三方专属客户',},
        {value:100,name:'其他',},
      ],
      sexList:[
        {value:1000,name:'男',},
        {value:1200,name:'女',},
      ],
      lineXDataList:['2023-01', '2023-02', '2023-03', '2023-04'],
      lineYDataList:[{
        name: 'Email',
        type: 'line',
        stack: 'Total',
        data: [120, 132, 101, 134]
      },
        {
          name: 'Union Ads',
          type: 'line',
          stack: 'Total',
          data: [220, 182, 191, 234,]
        },
        {
          name: 'Video Ads',
          type: 'line',
          stack: 'Total',
          data: [150, 232, 201, 154]
        },
        {
          name: 'Direct',
          type: 'line',
          stack: 'Total',
          data: [320, 332, 301, 334]
        },
        {
          name: 'Search Engine',
          type: 'line',
          stack: 'Total',
          data: [820, 932, 901, 934]
        }],
      userList: [
        {
          value: '1',
          label: '员工1'
        }, {
          value: '2',
          label: '员工2'
        }
      ],
      selectedRange: 'today',
      tableHeight:600,
      tableColumns: [
        {key: 'name', label: `指定监测群成员`, visible: true, minWidth: 150, fixed: true},
        {key: 'mobile', label: `创建者`, visible: true, minWidth: 150, fixed: false},
        {key: 'email', label: `加入监测时间`, visible: true, minWidth: 200},
        {key: 'last_login_time', label: `监测群聊`, visible: true, minWidth: 200},
        {key: 'create_time', label: `累计发言数`, visible: true, minWidth: 200,showHeaderTip:'该成员在所有监测群的累计发言数',},
        {key: 'check_payCreate_time', label: `平均发言数`, visible: true, minWidth: 200,showHeaderTip:'指定成员累计发言数 / 监测群聊数',},
        {key: 'check_payStatus_name', label: `平均发言占比`, visible: true, minWidth: 150,showHeaderTip:'指定成员累计发言数 / 所有监测群聊发言数 * 100%，保留两位小数',},
        {key: 'msg', label: `备注`, visible: true, minWidth: 150},
      ],
      tableDataList: [],
      total: 8, // 表格的总条数
    }
  },
  watch: {},
  computed: {
    dateRange() {
      const now = new Date();
      switch (this.selectedRange) {
        case 'yesterday':
          return [
            new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1),
            new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1),
          ];
        case 'today':
          return [
            now,
            new Date(now.getFullYear(), now.getMonth(), now.getDate()),
          ];
        case 'last7Days':
          return [
            new Date(now.getTime() - (6 * 24 * 60 * 60 * 1000)),
            now,
          ];
        case 'last15Days':
          return [
            new Date(now.getTime() - (14 * 24 * 60 * 60 * 1000)),
            now,
          ];
        case 'last30Days':
          return [
            new Date(now.getTime() - (29 * 24 * 60 * 60 * 1000)),
            now,
          ];
        default:
          return [];
      }
    },
  },
  created() {
    //this.getList();
    this.tableDataList=[];
    for (let i=0; i<2;i++){
      let obj={
        name:'小红',
        mobile:'18207418337',
        email:'2572513931@qq.com',
        last_login_time:'锐行科技',
        create_time:'2012-02-12',
        check_payCreate_time:'一般',
        check_payStatus_name:'核心',
        account_infoStatus_name:'2012-09-13',
        all_num:'微信',
        open_num:'一般',
        check_num:'2012-09-12',
        waiting_coin:'2012-08-23',
        operate:true,
      }
      this.tableDataList.push(obj);
    }
  },
  methods: {
    handerAdd(){
     this.showAddUser=true;
    },
    getTime(type) {
      this.selectedRange = type;
      setTimeout(() => {
        console.log('时间范围', this.dateRange);
        this.timeRange = [];
        this.timeRange = [this.fiterTime(this.dateRange[0]), this.fiterTime(this.dateRange[1])];
        console.log('转化时间', this.timeRange);
      }, 0)
    },
    fiterTime(value) {
      if (!value) return '';
      const date = new Date(value);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleSetting(row){
     this.showMonitorData=true;
    },
  },
}
</script>


<style scoped lang="scss">
.title {
  display: flex;
  align-items: center;
  padding: 16px 0 0;
  font-weight: bold;
  font-size: 16px;
  margin-bottom:15px;
  position: relative;

  .icon {
    font-size: 12px;
    font-weight: 400;
    color: #3070ff;
    margin-left: 10px;
  }
  .time {
    position: absolute;
    right: 0px;
    top: 10px;
    color: #8C8C8C;
    font-size: 12px;
    font-weight: 400;
  }
}

.timeType {
  display: flex;
  align-items: center;
  margin-right: 10px;

  li {
    border: 1px solid #eee;
    height: 32px;
    margin: 0;
    padding: 0 15px;
    list-style: none;
    cursor: pointer;

    &.active {
      border-color: #2d8cf0;
      color: #2d8cf0;
    }
  }
}

.time-big {
  display: flex;
  align-items: center;
}
.formGroup {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
}
.center-title {
  height: 30px;
  display: flex;
  align-items: center;
  span {
    content: "";
    width: 4px;
    height: 14px;
    background-color: #3070ff;
    display: block;
    margin-right: 5px;
  }
}
.tableAnalysis {
  padding-bottom: 20px;
  position: relative;
  .center-title {
    margin-bottom: 20px;
  }
  .exportData {
    position: absolute;
    right: 0px;
    top: 0px;

  }
}
.tips {
  font-weight: 400;
  font-size: 14px;
  margin-left: 10px;
}
.search {
  display: flex;

  ::v-deep.el-input__inner {
    border-right: none !important;
    border-radius: 4px 0px 0px 0px;
  }

  ::v-deep .el-button--default {
    border-radius: 0px 4px 4px 0px;
    padding: 0px 10px;
  }
}
.userInfo {
  border-radius: 4px;
  margin: 8px 0;
  cursor: pointer;
  position: relative;
  padding-left: 50px;
  font-size: 14px;
  list-style: none;
  text-align: left;
  display: flex;
  align-items: center;
  justify-items: center;
  min-height:40px;

  img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    left: 0px;
    top: 0px;
    position: absolute;
  }

  .label {
    margin-top: 2px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f90;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .user-big {
    display: flex;
    flex-direction: column;
    line-height: 18px;
  }
}
</style>
